package model;


/**
 * A type of ownable field where the rent is determined by the number of shipping fields the player has.
 * @author Group 20
 *
 */
public class Shipping extends Ownable
{
	final private int RENT = 500;
	private int numOfFieldTypeOwned;
	
	/**
	 * Constructor
	 * @param number: Field number
	 * @param name: Field name
	 * @param description: Field description
	 * @param price: Field price
	 */
	public Shipping(int number, String name,String description, int price) 
	{
		super(number, name, description, price);
	}

	/**
	 * Calculates the rent based on the amount of shipping fields and returns it.
	 */
	@Override
	public int rent() 
	{
		return (int)(RENT*Math.pow(2.0, (double)numOfFieldTypeOwned-1));
	}

	/**
	 * Returns if the player has enough money for the rent on the field and withdraws it if he has.
	 */
	@Override
	public boolean landOnField(Player player, int dicesSum, int numOfFieldTypeOwned) 
	{
			
		if (owner != null)
		{
			if (owner.equals(player) || pawned)
				this.payment = 0;
			
			else
				payment = rent();
			
			if (!pawned)
			{
				if (player.getBalance()>=payment)
				{
					this.numOfFieldTypeOwned = numOfFieldTypeOwned;
					player.withdraw(rent());
					owner.deposit(rent());
					return true;
				}
			}
			return false;
		}
		return true;
	}
	
	
	/**
	 * toString Method
	 */
	@Override
	public String toString() {
		return "Shipping [RENT=" + RENT + ", numOfFieldTypeOwned="
				+ numOfFieldTypeOwned + "]";
	}

	/**
	 * Returns the price of the shipping to calculate the valueOfAssets
	 */
	@Override
	public int valueOfAssets() 
	{
		return price;
	}

	/**
	 * Returns zero houses since they can't be built on shipping fields
	 */
	@Override
	public int numOfHouses() {
		return 0;
	}

	/**
	 * Returns zero hotels since they can't be built on shipping fields
	 */
	@Override
	public int numOfHotels() {
		return 0;
	}

	/**
	 * Returns if the field is pawned or not.
	 */
	@Override
	public boolean isPawned() 
	{
		return pawned;
	}

	
	
}
